<?php

namespace App\Jobs\Plane\PlaneOrder;

use App\Models\Plane\PlaneOrders\PlaneOrder;
use App\Models\Plane\PlaneOrders\Repositories\Interfaces\PlaneOrderRepositoryInterface;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessPlaneOrderAutoCancel implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private PlaneOrder $order;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(PlaneOrder $order)
    {
        $this->order = $order;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $orderRepo = app(PlaneOrderRepositoryInterface::class);
        if ($this->order->isCancel()) {
            return;
        }
        $orderRepo->cancelOrder($this->order, false);
    }
}
